package snmptest.discover;

import java.util.List;
import java.util.Vector;

import com.isnmp.common.snmp.SNMPFactory;
import com.isnmp.common.snmp.SNMPTarget;
import com.isnmp.nms.framework.discover.DeviceInfo;
import com.isnmp.nms.framework.discover.DiscoverAPI;

public class IPDiscover {

    public static void main(String[] args) {
        System.out.println("init...");
        initSNMP();
        System.out.println("ip discovery");
        testSearchDeviceByIP();
    }

    static void initSNMP() {
        try {
            SNMPFactory.init(1, null, 8088);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public static void testSearchDeviceByIP() {
        try {
            List<SNMPTarget> snmpTargetList = new Vector<SNMPTarget>();
            SNMPTarget target1 = new SNMPTarget();
            target1.port = 161;
            target1.readCommunity = "public";
            target1.snmpVersion = SNMPTarget.VERSION1;
            snmpTargetList.add(target1);

            SNMPTarget target2 = new SNMPTarget();
            target2.port = 161;
            target2.readCommunity = "public";
            target2.snmpVersion = SNMPTarget.VERSION2C;
            snmpTargetList.add(target2);
            List<DeviceInfo> deviceList = DiscoverAPI.getDiscoverAPI().searchDevice("172.168.1.1", "172.168.1.254", snmpTargetList, true);
            // List<DeviceInfo> deviceList=
            // DiscoverAPI.getDiscoverAPI().searchDevice("192.168.174.1","192.168.174.2",
            // snmpTargetList,true);
            System.out.println("发现设备数" + deviceList.size());
            for (DeviceInfo device : deviceList) {
                System.out.println(device.getDeviceName());
                System.out.println(device.getDeviceDesc());
                System.out.println(device.getDeviceIP());
                System.out.println("MAC:" + device.getDeviceMAC());
                System.out.println("discover type:" + device.getDeviceProtocol());
                System.out.println("" + device.getDeviceSysOID());
                System.out.println(device.getDeviceType().getDeviceProductType());
                System.out.println("-----------------");
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
